<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String orderNo = request.getParameter("orderNo");
%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta content="B2B电商平台" name="description" />
<meta content="B2B电商平台" name="keyword" />

<title>B2B电商平台.店铺商品类型维护</title>
<link rel="icon" href="include/images/icss.ico" type="image/x-icon" />
<link rel="shortcut icon" href="include/images/icss.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/global.css" />
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/style.css" />
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/pro.css" />
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/proManage.css" />
<link rel="stylesheet" href="<%=path%>/include/JQuery ui/css/smoothness/jquery-ui-1.7.3.custom.css" type="text/css"></link>
<link rel="stylesheet" type="text/css" href="<%=path%>/include/pagination/page.css" media="all">
<link rel="stylesheet" type="text/css" href="<%=path%>/include/css/mmt_trading.css" />
<link rel="stylesheet" type="text/css" href="http://style.org.hc360.com/js/build/source/widgets/wij/hc.wijmo.css" />
<link rel="stylesheet" type="text/css" href="http://style.org.hc360.com/js/build/source/widgets/wij/hc.wijcalendar.css" />
<script type="text/javascript" src="<%=path %>/include/js/jquery-1.8.0.min.js"></script>
<script src="<%=path %>/include/wijmo/external/jquery-ui-1.8.23.custom.min.js" type="text/javascript"></script>
<script src="<%=path %>/include/wijmo/external/globalize.min.js" type="text/javascript"></script>
<script src="<%=path %>/include/wijmo/external/cultures/globalize.cultures.js" type="text/javascript"></script>
<script src="<%=path %>/include/wijmo/wijmo/jquery.wijmo.wijpopup.js" type="text/javascript"></script>
<script src="<%=path %>/include/wijmo/wijmo/jquery.wijmo.wijcalendar.js" type="text/javascript"></script>
<script type="text/javascript" src="<%=path %>/include/js/cookies.js"></script>
<script type="text/javascript" src="<%=path %>/include/js/icss.busin.js"></script>
<script type="text/javascript" src="<%=path %>/include/js/icss.common.js"></script>
<script type="text/javascript" src="<%=path%>/include/pagination/jquery.pagination.js"></script>
<script type="text/javascript" src="<%=path%>/include/pagination/init.js"></script>
<script type="text/javascript" src="<%=path%>/include/js/doT.min.js"></script>
<script type="text/javascript" src="<%=path%>/include/layer/layer.js"></script>
<script type="text/javascript" src="<%=path%>/include/js/json2.js"></script>
<script type="text/javascript" src="<%=path%>/include/js/calcul.js"></script>

<style type="text/css">
.price a.price_rise {
	background-position: -62px -136px;
}

.price a.price_drop {
	background-position: -62px -95px;
}

.price a.price_null {
	background-position: -62px -15px;
	padding-right: 0px;
}

.expire a.expire_drops {
	background-position: -61px -95px;
}

.expire a.expire_rise {
	background-position: -61px -136px;
}

.expire a.expire_null {
	background-position: -61px -15px;
	padding-right: 0px;
}

.colnums-2-ab-b {
	float: left;
	width: 100%;
	height: auto;
	font-size: 12px !important;
}

.listed_tb_k th.t1 {
	width: 44%;
	border-right: 0px solid #fff;
	padding: 0 5px;
}

.listed_tb_k th.t2 {
	width: 8%;
	border-right: 0px solid #fff;
}

.listed_tb_k th.t3 {
	width: 8%;
	border-right: 0px solid #fff;
}

.listed_tb_k th.t4 {
	width: 12%;
	border-right: 0px solid #fff;
}

.listed_tb_k th.t5 {
	width: 12%;
	border-right: 0px solid #fff;
}

.listed_tb_k th.t6 {
	width: 8%;
	border-right: 0px solid #fff;
}

.listed_tb_k th.t7 {
	width: 8%;
	border-right: 0px solid #fff;
}

.productName {
	border: 1px solid #FFF;
	width: 300px;
	height: 50px;
	display: table-cell;
	vertical-align: middle;
	text-align: center;
	background-color: #fff;
}

.listed_tb_k tbody td.t2 .pic_50 {
	border: 1px solid #FFF;
	width: 50px;
	height: 50px;
	display: table-cell;
	vertical-align: middle;
	text-align: center;
	background-color: #fff;
}

.t4 {
	border-right: 1px solid #ddd;
}

.t5 {
	border-right: 1px solid #ddd;
}

.t6 {
	border-right: 1px solid #ddd;
}

.t7 {
	border-right: 1px solid #ddd;
}

#priceList td {
	border: 1px solid #ddd;
}

thead th {
	border: 1px solid #ddd;
	padding: 4px;
}

.i_top input {
	height: 24px;
}

.sear {
	border: 1px solid #e0e0e0;
	background: #f5f5f5;
	margin-top: 10px;
	height: 80px;
	line-height: 40px;
	font-size: 14px;
}

</style>

<script type="text/javascript">
	$(document).ready(function() {
		_queryList();
	});

    var pagination;
	function _queryList(){
  		var url = "<%=path %>/orderList/getOrderListByOrderNo.do?orderNo=<%=orderNo%>";
  		pagination = _initPagination({'pageId':'pagination', 'cKey':'toOrderList','url': url, 'rows': 10, 'callback':_initDataList});
  		
	}
	function _initDataList(data) {
		var jStr = JSON.stringify(data);
		var rjs = jStr.replace(/"/g,"#@");
 		var d = data.rows;
 		var str = "";
		$("#priceList").empty();
		var sumRealMoneySpan = '';
		var deliverMoneySpan = '';
		var discountMoneySpan = ''; 
		var totalRealMoneySpan = '';
		var addressSpan = '';
	
		for(var i=0;i<d.length;i++){
			//第一条商品信息
			var num = d[i].products.length;//单个订单商品个数
			if(d[i].products.length>0){
				for(var j = 0;j<num;j++){
					str +="<tr>";
					str +="		<td  style='text-align:center;vertical-align: middle;'>";
					str +="			<div  style='float:left;padding: 2px;'>";
					if(d[i].products[j].PRODUCT_PIC==undefined){
						str += "        		<img src='<%=path%>/download/error/nopicture.jpg' width='50' height='43.5' alt='' resizeimg='true' onmousedown='' onerror='javascript:this.src=\"<%=path%>/download/error/nopicture.jpg\";' style='width: 50px; height: 43.5px;'>";
					} else {
						str +=" 				<img src='"+d[i].products[j].PRODUCT_PIC+"' width='50' height='50' alt='' resizeimg='true' onmousedown='' onerror='javascript:this.src=\"<%=path%>/download/error/nopicture.jpg\";' style='width: 50px; height: 43.5px;'>";
					}
					str +=" 		</div>";
					str +=" 		<div  style='text-align: left;float:left;vertical-align: middle;padding-top:15px;'>";
					str +=" 			<p>"+ d[i].products[j].PRODUCT_NAME +"</p>";
					str +=" 		</div>";
					str +=" 	</td>";
					str +=" 	<td style='text-align:center;vertical-align: middle' >"+ d[i].products[j].PRODUCT_PRICE +"</td>";
					str +="		<td style='text-align:center;vertical-align: middle' >"+ d[i].products[j].SELL_AMOUNT +"</td>";
					if(num>0&&j==0){
						str +="		<td style='text-align:center;vertical-align: middle;' rowspan='"+num+"'>"+ accSub(parseFloat(d[i].SUM_REAL_MONEY),parseFloat(d[i].DELIVER_MONEY)) +"</td>";
						str +="		<td style='text-align:center;vertical-align: middle;' rowspan='"+num+"'>";
						str +='			<input id="discount" style="width:50px;" onpropertychange="textChange(\'discount\');" oninput="textChange(\'discount\');" onkeyup="javascript:setShowLength(this, 64, \'titleLen1\');">';
						str +='			&nbsp;折&nbsp;=&nbsp';
				//		str +='			<input id="discountMoney" style="width:40px;" onpropertychange="textChange(\'discountMoney\',\''+ d[i].SUM_REAL_MONEY +'\');" oninput="textChange(\'discountMoney\',\''+ d[i].SUM_REAL_MONEY +'\');">';
						str +='			<input id="discountMoney" style="width:50px;" onBlur="textChange(\'discountMoney\');" value="' + d[i].YH_MONEY + '">';
						str +="		</td>";
						str +="		<td style='text-align:center;vertical-align: middle;' rowspan='"+num+"'>";
						str +='			快递</br><input id="deliverMoney" style="width:50px;text-align:center;" onpropertychange="textChange(\'deliverMoney\');" oninput="textChange(\'deliverMoney\');" onkeyup="javascript:setShowLength(this, 64, \'titleLen1\');" value="' + d[i].DELIVER_MONEY + '">';
						str +="			</br>直接输入</br>邮费金额";
						str +="		</td>";
					}
					str +="</tr>";
				}
			}
			sumRealMoneySpan = accSub(parseFloat(d[i].SUM_REAL_MONEY),parseFloat(d[i].DELIVER_MONEY));
		//	deliverMoneySpan = '0';
		//	discountMoneySpan = '- 0'; 
		//	totalRealMoneySpan = d[i].SUM_REAL_MONEY;
			addressSpan = d[i].PROVINCE + '&nbsp;' + d[i].CITY + '&nbsp;' + d[i].COUNTY + '&nbsp;' + d[i].CON_ADDRESS ;
		}
		$("#sumMoney").val(sumRealMoneySpan);
		$("#sumRealMoneySpan1").html(sumRealMoneySpan);
		$("#sumRealMoneySpan2").html(sumRealMoneySpan);
	//	$("#deliverMoneySpan").html(deliverMoneySpan);
	//	$("#discountMoneySpan").html(discountMoneySpan);
	//	$("#totalRealMoneySpan").html(totalRealMoneySpan);
		
		$("#addressSpan").html(addressSpan);
		$("#priceList").append(str);
		textChange("discountMoney");
		_reHeight("rightFrame", "contentDiv");
		//_reHeight();
	 }
	
	function discountTip(){
	//	layer.tips('负数代表优惠折扣', '#discountImg');
		
		layer.tips('负数代表优惠折扣', '#discountImg', {
			tips: [1, 'orange'],
			time: 4000
		});
	}
	
	function textChange(name){
		var sumMoney = $("#sumMoney").val();
		var discount = $("#discount").val();
		var discountMoney = $("#discountMoney").val();
		var deliverMoney = $("#deliverMoney").val();
		var resultMoney = 0;
		var totalMoney = 0;
		var flag = "-";
		if(name == "discount"){
			if(discount != '' && checkNum(discount)){
				if(deliverMoney == ''){
					deliverMoney = '0';
				}
				resultMoney = parseFloat(discount/10) * parseFloat(sumMoney);
				resultMoney = resultMoney.toFixed(2);
				totalMoney = parseFloat(resultMoney) + parseFloat(deliverMoney);
				if(parseFloat(10) < parseFloat(discount)){
					flag = "+";
					discountMoney = parseFloat(resultMoney) - parseFloat(sumMoney);
				}else{
					flag = "-"
					discountMoney = parseFloat(sumMoney) - parseFloat(resultMoney);
				}
				discountMoney = discountMoney.toFixed(2);
				$("#discountMoney").val(flag + discountMoney);
				$("#discountMoneySpan").html(flag + " " + discountMoney);
				$("#deliverMoneySpan").html(parseFloat(deliverMoney).toFixed(2));
				$("#totalRealMoneySpan").html(totalMoney.toFixed(2));
			}
		}
		var increaseRegu = /^(\+)?\d+(\.\d+)?$/;
		var decreaseRegu = /^(\-)\d+(\.\d+)?$/;
		if(name == "discountMoney"){
			if(deliverMoney == ''){
				deliverMoney = '0';
			}
			if(discountMoney == ''||discountMoney == undefined){
				discountMoney = '0';
			}
			if(discountMoney != '' && validation(discountMoney)){
				var money = Math.abs(discountMoney);
				if (decreaseRegu.test(discountMoney)) {
					flag = "-";
					discount = (parseFloat(sumMoney) - parseFloat(money))/parseFloat(sumMoney)*10;
					totalMoney = parseFloat(sumMoney) - parseFloat(money) + parseFloat(deliverMoney);
				}else if (increaseRegu.test(discountMoney)) {
					flag = "+";
					discount = (parseFloat(sumMoney) + parseFloat(money))/parseFloat(sumMoney)*10;
					totalMoney = parseFloat(sumMoney) + parseFloat(money) + parseFloat(deliverMoney);
				}
				discount = discount.toFixed(1);
				$("#discount").val(discount);
				$("#discountMoneySpan").html(flag + " " + parseFloat(money).toFixed(2));
				$("#deliverMoneySpan").html(parseFloat(deliverMoney).toFixed(2));
				$("#totalRealMoneySpan").html(totalMoney.toFixed(2));
			}
		}
		if(name == "deliverMoney"){
			if(checkNum(deliverMoney)){
				if(deliverMoney == ''){
					deliverMoney = '0';
				}
				if(discount != ''){
					var money = Math.abs(discountMoney);
					if(increaseRegu.test(discountMoney)){
						totalMoney = parseFloat(sumMoney) + parseFloat(money) + parseFloat(deliverMoney);
					}else {
						totalMoney = parseFloat(sumMoney) - parseFloat(money) + parseFloat(deliverMoney);
					}
				}else{
					totalMoney = parseFloat(sumMoney) + parseFloat(deliverMoney);
				}
				$("#deliverMoneySpan").html(parseFloat(deliverMoney).toFixed(2));
				$("#totalRealMoneySpan").html(totalMoney.toFixed(2));
			}
		}
	}
	
	function setShowLength(obj, maxlength, id){
//		var rem = maxlength - obj.value.length;//可显示剩余可输字数
		var rem = obj.value;
		checkNum(rem);
	}
	function setShowLength1(obj, maxlength, id){
//		var rem = maxlength - obj.value.length;//可显示剩余可输字数
		var rem = obj.value;
		validation(rem);
	}
	
	function checkNum(tempOrder){
		if(isNaN(tempOrder)){
			 alert('参数值只能为数字型!');  	
			 return false;
		}
		return true;
	}
	function validation(num) {
		var regu = /^(\-|\+)?\d+(\.\d+)?$/;
		if (num != "") {
			if (!regu.test(num)) {
				alert('参数格式不对(可以为0,正数或负数)！');
				return false;
			}
		}
		return true;
	}
	function isNum(a){
		var reg =/^[0-9]\d*$/;
		return reg.test(a);
	}
	
	function free(){
		$("#deliverMoney").val("0");
		textChange('deliverMoney',$("#sumMoney").val());
	}
	
	function setValues(){
		var discountMoney = $("#discountMoney").val();
		var deliverMoney = $("#deliverMoney").val();
		parent.$('#finalDiscountOrderNo').val('<%=orderNo%>');
		parent.$('#finalDiscountMoney').val(discountMoney);
		parent.$('#finalDeliverMoney').val(deliverMoney);
		var sum_real_money = $("#totalRealMoneySpan").html()
		parent.$('#sum_real_money').val(sum_real_money);
	}
</script>
</head>

<body style="font-family: '微软雅黑'">
	<input id="sumMoney" name="sumMoney" type="hidden">
	<div id="priceDiv">
		<div id="editPriceDiv" style="padding:10px 20px;">
			<div><span style="font-weight:bold;">订单原价</span>(不含运费)：<span id="sumRealMoneySpan1" style="color:orange;"></span>&nbsp;元</div>
			<div class="listed_tb_k" style="margin:0 0 5px 0;width: 99.5%;border: none;">
				<table cellspacing="0" cellpadding="0" width="100%">
					<thead>
						<tr>
							<th style="text-align:center;vertical-align: middle;width:30%;">宝贝</th>
							<th style="text-align:center;vertical-align: middle;width:10%;">单价(元)</th>
							<th style="text-align:center;vertical-align: middle;width:10%;">数量</th>
							<th style="text-align:center;vertical-align: middle;width:10%;">原价(元)</th>
							<th style="text-align:center;vertical-align: middle;width:30%;">涨价或折扣<img/>
								<img id="discountImg" src="<%=path%>/include/images/discount.png" title="负数代表优惠折扣" onclick="discountTip()" style="width: 16px; height: 16px;">
							</th>
							<th style="text-align:center;vertical-align: middle;width:10%;">邮费(元)</th>
						</tr>
					</thead>
					<tbody id="priceList">
					</tbody>
				</table>
			</div>
			<div>
				收货地址：<span id="addressSpan"></span><br>
				买家实付：<span id="sumRealMoneySpan2" style="font-size:16px;"></span> + <span id="deliverMoneySpan" style="font-size:16px;"></span> <span id="discountMoneySpan" style="color:green; font-size:16px;"></span> = <span id="totalRealMoneySpan" style="color:orange; font-size:16px;"></span> 元
				<br>
				<div style="float:right;">
					<img src="<%=path%>/include/images/pencil.png"  alt="" onclick="free()" style="cursor:pointer;width: 14px; height: 14px;"><span style="color:blue;cursor:pointer;" onclick="free()">免运费</span>
				</div>
				<span style="color:grey;">买家实付 = 原价 + 运费 + 涨价或折扣</span><br>
				<span style="color:grey;">邮费为0时货到付款服务费将由卖家承担</span><br>
				<span style="color:grey;">店铺优惠**元已均摊到每个宝贝，并计算在单个宝贝的折扣中</span><br>
				
			</div>
		</div>
	</div>
	
</body>
</html>
